/*
 * Copyright (C) 2020 Baidu, Inc. All Rights Reserved.
 */
package com.wty.basic.errordemo;

import org.junit.Test;

/**
 * @Author wangtengyu
 * @Date 2020/7/29 11:22 上午
 * @Description
 */
public class ExceptionDemo {

    @Test
    public void test() throws Exception {
        Exception e = null;
        try {
            throw new RuntimeException("error first");
        } catch (Exception ex) {
            e = ex;
        } finally {
            try {
                throw new RuntimeException("error in finally");
            } catch (Exception ex) {
                if (null != e) {
                    e.addSuppressed(ex);
                } else {
                    e = ex;
                }
            }
        }
        if (null != e) {
            throw e;
        }
    }
}
